package indi.cyh.fastservice.tool;

import com.alibaba.fastjson.JSONObject;
import indi.cyh.fastservice.base.entity.http.ParamMode;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Map;

/**
 * @Description TODO
 * @Author CYH
 * @Date 2021/10/25 14:30
 **/
@Component
@Slf4j
public class RequestTool {

    public HttpUriRequest get(String url, Map<String, Object> headerParamMap) throws URISyntaxException, IOException {
        log.info("请求地址: {}", url);
        // 定义请求的参数
        URI uri = new URIBuilder(url).build();
        // 创建http GET请求
        HttpGet httpGet = new HttpGet(uri);
        for (String key : headerParamMap.keySet()) {
            httpGet.addHeader(key, headerParamMap.get(key).toString());
        }
        return httpGet;
    }

    public HttpUriRequest post(String url, Map<String, Object> bodyParams, Map<String, Object> headerParamMap, ParamMode paramMode) {
        log.info("头部参数值: {}", JSONObject.toJSONString(headerParamMap));
        log.info("参数值: {}", JSONObject.toJSONString(bodyParams));
        HttpPost httpPost = new HttpPost(url);


        return null;
    }
}
